/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package atm;

import java.awt.event.ActionEvent;

/**
 *
 * @author Jose Gabriel
 */
public class JPanelTeclado extends javax.swing.JPanel {

    Boton botones[];
    String buffer="",texto="";
    
    /**
     * Creates new form JPanelTelado
     */
    public JPanelTeclado() {
        initComponents();

        
        botones = new Boton[12];
        
        for(int i=0,posx=0,posy=0 ; i<botones.length ; i++ , posx++){
            
            //Crear botones en el arreglo y asignarle evento o no según corresponda
            botones[i] = new Boton(){

                @Override
                public void evento(ActionEvent event) {
                    if(!action){
                        //Agregar el numero a buffer
                        buffer += this.getValue();
                        System.out.println(buffer);
                    }else if(this.getText().compareTo("<-")==0){
                        //Ejecutar el metodo correspondiente
                        if(buffer.length()>=1){
                            buffer = buffer.substring(0, buffer.length()-1);
                        }                        
                        System.out.println(buffer);
                    }else if(this.getText().compareTo("->")==0){
                        //Ejecutar el metodo correspondiente
                        texto=buffer;
                        buffer="";
                        System.out.println(texto);
                    }
                }
                
            };
            
            botones[i].iniciar();
            this.add(botones[i]);
            if(i<9){
                botones[i].setText(i+1+"");
            }else if(i==9){
                botones[i].setText("<-");
                botones[i].setAction(true);
            }else if(i==10){
                botones[i].setText("0");
            }else if(i==11){
                botones[i].setText("->");
                botones[i].setAction(true);
            }
            
            //Ordenar botones en cuadricula
            if( i>0 && i%3==0){
                posx=0;
                posy++;
            }
            botones[i].setBounds(posx*50+10,posy*30+10, 50, 30);
            
        }        
    }

    public String getTexto() {
        return this.texto;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
